/**
 * GroupUserServiceImpl.java
 * @author
 * 作者 屈甲康 
 */
package org.jackysoft.service.impl;

import java.util.Collection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jackysoft.entity.GroupUser;
import org.jackysoft.entity.User;
import org.jackysoft.service.AbstractStringIdServiceImpl;
import org.jackysoft.service.GroupUserService;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class GroupUserServiceImpl extends AbstractStringIdServiceImpl<GroupUser>
implements GroupUserService {
    /**
	 * 
	 */
	private static final long serialVersionUID = 616735073949593528L;
	final static Log logger = LogFactory.getLog(GroupUserServiceImpl.class);

	public GroupUserServiceImpl(){
	    this.type = GroupUser.class;
	}

	@Override
	public Collection<GroupUser> get(User owner) throws DataAccessException {
		String hql=String.format("from %s g where g.owner=:owner ",entitytable());
		return query(hql).list();
	}

	@Override
	public Collection<User> fetchUsers(GroupUser gu) throws DataAccessException {
		gu = get(gu.getId());
		return gu.getUsers();
	}

	@Override
	public void appendUser(GroupUser gu, Collection<User> users)
			throws DataAccessException {
		gu = get(gu.getId());
		gu.getUsers().addAll(users);		
	}	
		
}